package com.tools.controller.user;


import com.tools.common.enums.ResultCode;
import com.tools.common.result.Result;
import com.tools.pojo.user.bo.RoleMenuBO;
import com.tools.pojo.user.po.RoleMenu;
import com.tools.service.user.RoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role-menu")
@AllArgsConstructor
@Tag(name = "角色菜单模块",description = "角色菜单模块")
public class RoleMenuController {

    private final RoleMenuService roleMenuService;


    @PostMapping("/add")
    @Operation(summary = "添加角色菜单",description = "添加角色菜单")
    @ApiResponse(responseCode = "200", description = "角色菜单添加成功")
    public Result<?> addRoleMenu(@RequestBody RoleMenuBO roleMenuBO) {
        Boolean result = roleMenuService.addRoleMenu(roleMenuBO);
        return result ? Result.success() : Result.fail(ResultCode.DATA_ADD_ERROR);
    }

    /**
     * 根据角色id 查询菜单列表
     */
    @PostMapping("/getMenuByRoleId")
    @Operation(summary = "根据角色id 查询菜单列表",description = "根据角色id 查询菜单列表")
    @ApiResponse(responseCode = "200", description = "角色菜单查询成功")
    public Result<?> getMenuByRoleId(@RequestBody RoleMenuBO roleMenuBO) {
        List<RoleMenu> roleMenuList = roleMenuService.lambdaQuery().eq(RoleMenu::getRoleId, roleMenuBO.getRoleId()).list();
        return Result.success(roleMenuList);
    }

}
